#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char arr[110][110];
int main()
{
	int n;
	while (scanf_s("%d", &n)) {
		if (n == 0) {
			break;
		}
		if (n == 1) {
			printf("%3d\n", 1);
			continue;
		}
		memset(arr, ' ', sizeof(arr));
		int k = 1;
		int up = 0, down = n - 1, left = 0, right = n - 1;
		/*for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				arr[i][j] = (char)' ';
			}
		}*/
		while (k <= 4 * n - 4) {
			for (int i = 0; i < n; i++) {
				arr[up][i] = (int)(k++);
			}
			for (int i = 1; i < n - 1; i++) {
				arr[i][right] = (int)(k++);
			}
			for (int i = n - 1; i >= 0; i--) {
				arr[down][i] = (int)(k++);
			}
			for (int i = n - 2; i >= 1; i--) {
				if (k==32) {
					arr[i][left] = (int)('32' - '0');
				}
				else {
					arr[i][left] = (int)(k++);
				}
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (arr[i][j] == ' ') {
					printf("%3c", arr[i][j]);
				}
				else {
					printf("%3d", arr[i][j]);
				}
			}
			printf("\n");
		}
	}
	return 0;
}